home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / fractals / apfelkiste / apfelkiste2.0 / source / apfelkiste2.0src.lzh / Apfelkiste.c < prev    next >
C/C++ Source or Header  |  1991-10-23  |  28KB  |  1,041 lines

  1. /************************************************************************/
  2. /* Apfel.c --- Generates an image of the Mandelbrot-set            */
  3. /*                                    */
  4. /* Author:    M. Böhnisch (BillySoft)                    */
  5. /*        Löher Str. 2                        */
  6. /*        D-4790 Paderborn                    */
  7. /*                                    */
  8. /*        billy@uni-paderborn.de.pbinfo                */
  9. /*======================================================================*/
  10. /* 06.11.89    iterative version with fixed box sizes (10 by 10),    */
  11. /*        adapted a GFA-BASIC program from a german magazine    */
  12. /*                                    */
  13. /* 08.11.89    complete own version with recursive algorithm        */
  14. /*        (divide & conquer)                    */
  15. /*                                    */
  16. /* 10.11.89    added user input of picture size and borders        */
  17. /*                                    */
  18. /* 11.11.89    minor bug fixing                    */
  19. /*                                    */
  20. /* 20.11.89    added fix-point arithmetik written in assembler        */
  21. /*        format:                            */
  22. /*                                    */
  23. /*            [sgn|xxx xxxx xxxx xxxx.xxxx xxxx xxxx xxxx]    */
  24. /*                                    */
  25. /*        not accurate enough.                    */
  26. /*                                    */
  27. /* 21.11.89    rewrote fix-point format to:                */
  28. /*                                    */
  29. /*            [sgn|xxx xxxx.xxxx xxxx xxxx xxxx xxxx xxxx]    */
  30. /*                                    */
  31. /*        nice! (I'll try to use 26 bit after the point sometime) */
  32. /*                                    */
  33. /* 28.11.89    found IFF-Library on Fish #173. save picture option    */
  34. /*        added.                            */
  35. /*                                    */
  36. /* 04.12.89    improved assembly program                */
  37. /*                                    */
  38. /* 07.12.89    slight optimization in recursion scheme            */
  39. /*                                    */
  40. /* 09.12.89    added input requester                    */
  41. /*                                    */
  42. /* 21.07.90    review for Aztek-C5.0a                    */
  43. /*                                    */
  44. /* 23.09.90    print option added (color printers)            */
  45. /*                                    */
  46. /* 25.09.90    added color requester                    */
  47. /*                                                                      */
  48. /* 27.09.90     optimization of assembly program                        */
  49. /*                                    */
  50. /* 15.11.90    review for SAS C5.10                    */
  51. /*                                    */
  52. /* 19.11.90    added a little retrying in case of an error by closing    */
  53. /*        screens. Might recover some problems with Amigas short    */
  54. /*        on memory or when really *BIG* screens are requested.    */
  55. /*                                    */
  56. /* 25.11.90    added s'more source code comments and translated all    */
  57. /*        strings from german to english                */
  58. /*                                    */
  59. /* 30.01.91    removed a bug causing to save no colormap along with a    */
  60. /*        picture                            */
  61. /*                                    */
  62. /* 01.02.91    removed a bug doing strange things while colorcycling    */
  63. /*        pictures with more than 5 BitPlanes            */
  64. /*                                    */
  65. /* 01.02.91    added configuration facilities                */
  66. /*                                    */
  67. /* 17.04.91    removed a bug preventing the "Multitasking OFF" to work    */
  68. /*                                    */
  69. /* 18.04.91    some cast - operators added in "printersupport.h" to    */
  70. /*        compile without warnings.                */
  71. /*                                    */
  72. /* 08.06.91    added 68030/68881 support                */
  73. /*                                    */
  74. /* 09.06.91    replaced lattice fp by fast floating point functions    */
  75. /*        (faster only if FLOAT is used. shorter object, though)    */
  76. /************************************************************************/
  77. /*                         W A R N I N G  ! ! !                */
  78. /*                                    */
  79. /* From now on ALL versions of Apfelkiste will need KS 2.0 and the new    */
  80. /* set of include files. This applies to version 28 and above.        */
  81. /************************************************************************/
  82. /*                                    */
  83. /* 12.06.91    switched to 2.0 at last. removed ARP routines, not    */
  84. /*        because they're bad (THEY AREN'T!), but because of    */
  85. /*        naming conflicts of arp.h to 2.0 include files.        */
  86. /*                                    */
  87. /* 12.06.91    added some all *new* facilities:            */
  88. /*            o automatic overscan adaption            */
  89. /*            o autoscrolling screen                */
  90. /*                                    */
  91. /* 22.07.91    2.0 style gadgets provided                */
  92. /*                                    */
  93. /* 23.07.91    located a bug in SAS's fscanf() (!!!), %hx does NOT     */
  94. /*        read 16 Bit integers but 32 Bit longs. Thus lead into    */
  95. /*        a strange error that occurred with pictures >3        */
  96. /*        bitplanes only: all colors above #8 are set to 0(black) */
  97. /*        Fixed by scanning into a temporary long first.        */
  98. /*                                    */
  99. /* 23.10.91    changed names of OpenIFF() and CloseIFF() to xOpenIFF()    */
  100. /*        and xCloseIFF() for KS 2.0 include file compatibility    */
  101. /*                                    */
  102. /*        updated docs for inclusion in AmigaLibDisk pool        */
  103. /*                                    */
  104. /*        last-minute review for SAS C5.10b            */
  105. /************************************************************************/
  106.  
  107. /* -------------------------------------------------------------------- */
  108. /* Some defininitions to take advantage of Lattice's LSR-code:        */
  109. /* -------------------------------------------------------------------- */
  110. long     _stack        = 20000;    /* Stack space for this task     */
  111. char    *_procname    = "Apfelkiste";    /* Name of process created    */
  112. long     _priority    = 0;        /* Process priority        */
  113. long     _BackgroundIO    = 0;        /* No stdio required        */
  114. /* -------------------------------------------------------------------- */
  115.  
  116. #define APFEL_VERSION    "30"
  117.  
  118. #include <exec/types.h>
  119. #include <exec/memory.h>
  120.  
  121. #include <intuition/intuition.h>
  122.  
  123. #include <graphics/gfx.h>
  124. #include <graphics/gfxmacros.h>
  125.  
  126. #include <libraries/iff.h>
  127. #include <libraries/asl.h>
  128. #include <libraries/color.h>
  129.  
  130. #include <proto/exec.h>
  131. #include <proto/dos.h>
  132. #include <proto/graphics.h>
  133. #include <proto/intuition.h>
  134. #include <proto/asl.h>
  135. #include <proto/gadtools.h>
  136.  
  137. #include <printersupport.h>
  138. #include <clib/macros.h>
  139. #include <string.h>
  140. #include <stdlib.h>
  141. #include <stdio.h>
  142. #include <dos.h>
  143. #include <mffp.h>
  144. #include <math.h>
  145. #include "Apf0.h"
  146. #include "Apf2.h"
  147.  
  148. /* -------------------------------------------------------------------- */
  149. /* Prototypes for the functions in the other modules            */
  150. /* -------------------------------------------------------------------- */
  151.  
  152. void FixPoint(    double rmin, double rmax, double imin, double imax,
  153.         double dx, double dy,
  154.         int maxiter, double divergenz, int gx, int gy, int depth);
  155. void __regargs    Apfel_Alert(long number);
  156. void __regargs    Activate_Gadget(struct Window *w, USHORT ID);
  157. void __regargs    Apfel_FLOAT(int x1, int y1, int x2, int y2);
  158. long         Iter_FLOAT(double r, double i);
  159. void        FreeGads(void);
  160. struct Gadget    *InitGads(struct Screen *scr);
  161.  
  162. /* --------------------------------------------------------------------- */
  163.  
  164. struct IntuitionBase    *IntuitionBase;
  165. struct GfxBase        *GfxBase;
  166. struct IFFBase        *IFFBase;
  167. struct Library        *AslBase;
  168. struct ColorBase    *ColorBase;
  169. struct Library        *GadToolsBase;
  170.  
  171. struct Screen        *s;
  172. struct Window        *w, *u;
  173. struct RastPort        *rp, *up;
  174. struct ViewPort        *vp;
  175. struct Gadget        *glist;
  176.  
  177. char             DefBuf_REAL0[40];
  178. char             DefBuf_REAL1[40];
  179. char             DefBuf_IMAG0[40];
  180. char             DefBuf_IMAG1[40];
  181. char             DefBuf_MAXITER[40];
  182. char             DefBuf_DIV[40];
  183. char             DefBuf_XSIZE[40];
  184. char             DefBuf_YSIZE[40];
  185. char             DefBuf_DEPTH[40]; 
  186.  
  187. extern long         SelNo_TASK;
  188. extern long         SelNo_CYCLE;
  189. extern char        *Buf_REAL0;
  190. extern char        *Buf_REAL1;
  191. extern char        *Buf_IMAG0;
  192. extern char        *Buf_IMAG1;
  193. extern char        *Buf_MAXITER;
  194. extern char        *Buf_DIV;
  195. extern char        *Buf_XSIZE;
  196. extern char        *Buf_YSIZE;
  197. extern char        *Buf_DEPTH;
  198. extern char        *DefText_REAL0;
  199. extern char        *DefText_REAL1;
  200. extern char        *DefText_IMAG0;
  201. extern char        *DefText_IMAG1;
  202. extern char        *DefText_MAXITER;
  203. extern char        *DefText_DIV;
  204. extern char        *DefText_XSIZE;
  205. extern char        *DefText_YSIZE;
  206. extern char        *DefText_DEPTH;  
  207.  
  208. int             cycle, task = TRUE;
  209. APTR             IFFfile = NULL;
  210. struct FileRequester    *FReq;
  211. union printerIO        *request;
  212. struct MsgPort        *printerPort;
  213.  
  214. int             gx, gy, xsize, ysize, depth, hide;
  215. short             maxcol;
  216. int             maxiter;
  217. double             divergenz, rmin, rmax, imin, imax, dx, dy;
  218.  
  219. /* -------------------------------------------------------------------- */
  220. /* All the stuff needed to comfortably get IntuitionMessages        */
  221. /* -------------------------------------------------------------------- */
  222.  
  223. ULONG             CLASS, CODE, GAD_ID;
  224. APTR             ADDR;
  225. struct IntuiMessage    *Message    = NULL;
  226.  
  227. ULONG GetMessage(struct Window *MW)
  228. {
  229.     CLASS = CODE = 0;
  230.     ADDR = NULL;
  231.     if ( Message = (struct IntuiMessage *) GetMsg(MW->UserPort) ) {
  232.         CLASS    = Message->Class;
  233.         CODE    = Message->Code;
  234.         ADDR    = Message->IAddress;
  235.         ReplyMsg((struct Message *) Message);
  236.     }
  237.     return CLASS;
  238. }
  239.  
  240. ULONG GT_GetMessage(struct Window *MW)
  241. {
  242.     CLASS = CODE = GAD_ID = 0;
  243.     ADDR = NULL;
  244.     if ( Message = GT_GetIMsg(MW->UserPort) ) {
  245.         CLASS    = Message->Class;
  246.         CODE    = Message->Code;        
  247.         ADDR    = Messa